// userPageB/pages/userStore/qualification/qualification.js
const app = getApp()
const WXAPI = require("../../../../api/api")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nvabarData: {
      showCapsule: 1, // 是否显示左上角图标   1表示显示    0表示不显示
      title: '商家资质', // 导航栏 中间的标题
      textColor: '#333333', // 标题颜色
      bgColor: '#ffffff', // 导航栏背景颜色
      isColor: true,
      isloading: false,
     
    },
    shopId:'',
    levelTipShow: false,
    WarningInfo: {},
    businessRiskShow: false,
    appealList:[],
    businessRiskList: [],
    businessRiskListShow: false,
    appealListShow: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    var shopId = options.shopId
    console.log('shopId',shopId)
    this.setData({
      shopId: shopId
    })
    this.getMerchantInfo()
    let str = 'abcdefg'
    const isHas = str.includes('h')
    console.log('isHas',isHas)
  },
  getMerchantInfo() { //获取商家资质
    var shopId = this.data.shopId
    console.log('shopId',shopId)
    var url = `/app/v1/customer/shop/merchantInfo/${shopId}`
    WXAPI.merchantQualification(url, '', res => {
      this.setData({
        merchantInfo: res.result,
        merchantId: res.result.merchantId
      })
      this.getGovWarningInfo()
    })
  },
  getGovWarningInfo() { //获取商家资质
    var merchantId = this.data.merchantId
    var url = `/app/v1/customer/shop/getGovWarningInfo/${merchantId}`
    WXAPI.getGovWarningInfo(url, '', res => {
      var appealList = []
      var businessRiskList = []
      if(res.result.appealList.length > 0) appealList.push(res.result.appealList[0])
      if(res.result.businessRiskList.length > 0)businessRiskList.push(res.result.businessRiskList[0])
      
      this.setData({
        WarningInfo: res.result,
        appealList: appealList ,
        businessRiskList: businessRiskList,
      })
      console.log('businessRiskList',this.data.businessRiskList)
    })
  },
  lookLevleTip(){ //商家等级说明
    this.setData({
      levelTipShow: true
    })
  },
  handlemore(e){
    var type = e.currentTarget.dataset.type
    console.log('type',type)
    var appealList = []
    var businessRiskList = []
    if(type == 'businessRiskList'){
      if(this.data.businessRiskListShow){
        businessRiskList.push(this.data.WarningInfo.businessRiskList[0])
      }else{
        businessRiskList = this.data.WarningInfo.businessRiskList
      }
      this.setData({
        businessRiskList: businessRiskList,
        businessRiskListShow: !this.data.businessRiskListShow
      })
    }else if(type == 'appealList'){
      if(this.data.appealListShow){
        appealList.push(this.data.WarningInfo.appealList[0])
      }else{
        appealList = this.data.WarningInfo.appealList
      }
      this.setData({
        appealList: appealList,
        appealListShow: !this.data.appealListShow
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})